home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / HyperCard Serial Toolkit 2.6 / Source Code / configureSPort.p < prev    next >
Encoding:
Text File  |  1995-02-07  |  7.0 KB  |  175 lines  |  [TEXT/MPS ]

  1. (*
  2.     configureSPort keyword,keyword, ... — Set the configuration of the port, as specified by a
  3.         keyword list. The following keywords are allowed:
  4.  
  5.                 modemPort/port1 - Use the modem port.
  6.                 printerPort/port2 - Use the printer port.
  7.                 baud300/baud600/baud1200/baud1800/baud2400/baud3600/
  8.                 baud4800/baud7200/baud9600/baud19200/baud57600 - Set the baud rate.
  9.                 stop10/stop15/stop20 - Set the number of stop bits to 1.0, 1.5, or 2.0.
  10.                 parityOff/parityOdd/parityEven - Set the parity.
  11.                 data5/data6/data7/data8 - Set the number of data bits.
  12.                 XOnOutOn/XOnOutOff - Enable or disable character flow control out outgoing data.
  13.                 CTSOutOn/CTSOutOff - Enable or disable signal flow control on outgoing data.
  14.                 linefeedOn/linefeedOff - Enable or disable sending of linefeeds after each carriage return.
  15.                 echoOn/echoOff - Enable or disable echoing of the input back to the output.
  16.                 editOn/editOff - Enable or disable editing of the input from the input (i.e., backspaces).
  17.                 stripOn/stripOff - Enable or disable striping of the top bit of the input.
  18.                 stripControlsOn/stripControlsOff - Enable or disable striping of control characters (except return and tab).
  19.                 autoWrapOn/autoWrapOff - Enable or disable automatic wrapping of input and output.
  20.  
  21.     To compile and link this file using Macintosh Programmer's Workshop,
  22.  
  23.         pascal -w configureSPort.p
  24.         link -m ENTRYPOINT -o HyperCommands -rt XCMD=7035 -sn Main=configureSPort ∂
  25.             configureSPort.p.o "{MPW}"Libraries:interface.o "{MPW}"Libraries:Libraries:HyperXLib.o
  26.  
  27.     © Copyright 1987,88,89 by Apple Computer, Inc.
  28.  
  29.     Initial coding 9/87 by Harry R. Chesley.
  30. *)
  31.  
  32. {$R-}
  33.  
  34. {$S configureSPort }     { Segment name must be the same as the command name. }
  35.  
  36. unit DummyUnit;
  37.  
  38. interface
  39.  
  40. uses MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;
  41.  
  42. procedure EntryPoint(paramPtr: XCmdPtr);
  43.     
  44. implementation
  45.  
  46. procedure configureSPort(paramPtr: XCmdPtr); forward;
  47.  
  48. procedure EntryPoint(paramPtr: XCmdPtr);
  49.  
  50.     begin
  51.         configureSPort(paramPtr);
  52.     end;
  53.  
  54. procedure configureSPort(paramPtr: XCmdPtr);
  55.  
  56.     var i: integer;
  57.         parmStr: str255;
  58.         hasChanged: boolean;
  59.  
  60.     procedure Fail(errMsg: Str255); { set theResult and quit }
  61.         begin
  62.             paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
  63.             exit(configureSPort);
  64.         end;
  65.  
  66.     {$I SPortUtil.inc}
  67.  
  68.     procedure changeByte(mask, value: longInt);
  69.  
  70.         begin
  71.             ThisSPort.byteConfig := BitOr(BitAnd(BitNot(mask),ThisSPort.byteConfig),value);
  72.         end;
  73.  
  74.     procedure updateIfChanged;
  75.         { If there have been any changes in the configuration, set the port. }
  76.  
  77.         begin
  78.             if hasChanged then
  79.                 begin
  80.                     { Save the settings. }
  81.                     Globals^^.ports[Globals^^.selectedPort] := ThisSPort;
  82.             
  83.                     { Open it if it hasn't already been opened. }
  84.                     EnsureOpenPort;
  85.                     { Set the port. }
  86.                     with ThisSPort do
  87.                         begin
  88.                             if SerHShake(portInDev,shakes) <> noErr then Fail('SerHShake failed');
  89.                             if SerHShake(portOutDev,shakes) <> noErr then Fail('SerHShake failed');
  90.                             if (SerReset(portInDev,byteConfig) <> noErr) or
  91.                                     (SerReset(portOutDev,byteConfig) <> noErr) then
  92.                                 Fail('SerReset failed');
  93.                         end;
  94.                     hasChanged := false;
  95.                 end;
  96.         end;
  97.  
  98.     procedure selectPort(whichPort: SPortSel);
  99.         { Switch to a new port. }
  100.  
  101.         begin
  102.             updateIfChanged;
  103.             Globals^^.selectedPort := whichPort;
  104.             ThisSPort := Globals^^.ports[whichPort];
  105.         end;
  106.  
  107.     begin
  108.         if paramPtr^.paramCount = 0 then Fail('no parameters');
  109.  
  110.         SetUpSPortGlobals;
  111.  
  112.         { Go through the configuration parameters, one by one...}
  113.         hasChanged := false;
  114.         with ThisSPort do
  115.             for i := 1 to paramPtr^.paramCount do
  116.                 begin
  117.                     GetStrParm(i,parmStr);
  118.                     if StringEqual(paramPtr,parmStr,'modemPort') or StringEqual(paramPtr,parmStr,'port1') then
  119.                         begin
  120.                             selectPort(sPortA);
  121.                             cycle;
  122.                         end
  123.                     else if StringEqual(paramPtr,parmStr,'printerPort') or StringEqual(paramPtr,parmStr,'port2') then
  124.                         begin
  125.                             selectPort(sPortB);
  126.                             cycle;
  127.                         end
  128.                     else if StringEqual(paramPtr,parmStr,'baud300') then changeByte($003FF,baud300)
  129.                     else if StringEqual(paramPtr,parmStr,'baud600') then changeByte($003FF,baud600)
  130.                     else if StringEqual(paramPtr,parmStr,'baud1200') then changeByte($003FF,baud1200)
  131.                     else if StringEqual(paramPtr,parmStr,'baud1800') then changeByte($003FF,baud1800)
  132.                     else if StringEqual(paramPtr,parmStr,'baud2400') then changeByte($003FF,baud2400)
  133.                     else if StringEqual(paramPtr,parmStr,'baud3600') then changeByte($003FF,baud3600)
  134.                     else if StringEqual(paramPtr,parmStr,'baud4800') then changeByte($003FF,baud4800)
  135.                     else if StringEqual(paramPtr,parmStr,'baud7200') then changeByte($003FF,baud7200)
  136.                     else if StringEqual(paramPtr,parmStr,'baud9600') then changeByte($003FF,baud9600)
  137.                     else if StringEqual(paramPtr,parmStr,'baud19200') then changeByte($003FF,baud19200)
  138.                     else if StringEqual(paramPtr,parmStr,'baud57600') then changeByte($003FF,baud57600)
  139.                     else if StringEqual(paramPtr,parmStr,'stop10') then changeByte($0C000,stop10)
  140.                     else if StringEqual(paramPtr,parmStr,'stop15') then changeByte($0C000,stop15)
  141.                     else if StringEqual(paramPtr,parmStr,'stop20') then changeByte($0C000,stop20)
  142.                     else if StringEqual(paramPtr,parmStr,'parityOff') then changeByte($03000,noParity)
  143.                     else if StringEqual(paramPtr,parmStr,'parityOdd') then changeByte($03000,oddParity)
  144.                     else if StringEqual(paramPtr,parmStr,'parityEven') then changeByte($03000,evenParity)
  145.                     else if StringEqual(paramPtr,parmStr,'data5') then changeByte($00C00,data5)
  146.                     else if StringEqual(paramPtr,parmStr,'data6') then changeByte($00C00,data6)
  147.                     else if StringEqual(paramPtr,parmStr,'data7') then changeByte($00C00,data7)
  148.                     else if StringEqual(paramPtr,parmStr,'data8') then changeByte($00C00,data8)
  149.                     else if StringEqual(paramPtr,parmStr,'XOnOutOn') then shakes.fXOn := 1
  150.                     else if StringEqual(paramPtr,parmStr,'XOnOutOff') then shakes.fXOn := 0
  151.                     else if StringEqual(paramPtr,parmStr,'CTSOutOn') then shakes.fCTS := 1
  152.                     else if StringEqual(paramPtr,parmStr,'CTSOutOff') then shakes.fCTS := 0
  153.                     else if StringEqual(paramPtr,parmStr,'linefeedOn') then sendLFs := true
  154.                     else if StringEqual(paramPtr,parmStr,'linefeedOff') then sendLFs := false
  155.                     else if StringEqual(paramPtr,parmStr,'echoOn') then doEcho := true
  156.                     else if StringEqual(paramPtr,parmStr,'echoOff') then doEcho := false
  157.                     else if StringEqual(paramPtr,parmStr,'editOn') then doEdit := true
  158.                     else if StringEqual(paramPtr,parmStr,'editOff') then doEdit := false
  159.                     else if StringEqual(paramPtr,parmStr,'stripOn') then stripIncoming := true
  160.                     else if StringEqual(paramPtr,parmStr,'stripOff') then stripIncoming := false
  161.                     else if StringEqual(paramPtr,parmStr,'stripControlsOn') then stripControls := true
  162.                     else if StringEqual(paramPtr,parmStr,'stripControlsOff') then stripControls := false
  163.                     else if StringEqual(paramPtr,parmStr,'autoWrapOn') then autoWrap := true
  164.                     else if StringEqual(paramPtr,parmStr,'autoWrapOff') then autoWrap := false;
  165.                     hasChanged := true;
  166.                 end;
  167.  
  168.         { Set it if it's been changed. }
  169.         updateIfChanged;
  170.         { And make sure the current port is open, even if we didn't change anything. }
  171.         EnsureOpenPort;
  172.     end;
  173.  
  174. end.
  175.